package com.ruoyi.web.controller.applet;

import com.ruoyi.applet.order.domain.OrdOrderCommodity;
import com.ruoyi.applet.order.service.IOrdOrderCommodityService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 订单商品Controller
 * @author ruoyi
 * @date 2025-01-02
 */
@Controller
@RequestMapping("/applet/ordOrderCommodity")
public class OrdOrderCommodityController extends BaseController {
    
    private final String prefix = "applet/ordOrderCommodity";
    
    @Resource
    private IOrdOrderCommodityService ordOrderCommodityService;
    
    @RequiresPermissions("applet:ordOrderCommodity:view")
    @GetMapping()
    public String ordOrderCommodity() {
        return prefix + "/ordOrderCommodity";
    }
    
    /**
     * 查询订单商品列表
     */
    @RequiresPermissions("applet:ordOrderCommodity:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(OrdOrderCommodity ordOrderCommodity) {
        startPage();
        List<OrdOrderCommodity> list = ordOrderCommodityService.selectOrdOrderCommodityList(ordOrderCommodity);
        return getDataTable(list);
    }
    
    /**
     * 导出订单商品列表
     */
    @RequiresPermissions("applet:ordOrderCommodity:export")
    @Log(title = "订单商品", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(OrdOrderCommodity ordOrderCommodity) {
        List<OrdOrderCommodity> list = ordOrderCommodityService.selectOrdOrderCommodityList(ordOrderCommodity);
        ExcelUtil<OrdOrderCommodity> util = new ExcelUtil<OrdOrderCommodity>(OrdOrderCommodity.class);
        return util.exportExcel(list, "订单商品数据");
    }
    
    /**
     * 新增订单商品
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }
    
    /**
     * 新增保存订单商品
     */
    @RequiresPermissions("applet:ordOrderCommodity:add")
    @Log(title = "订单商品", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(OrdOrderCommodity ordOrderCommodity) {
        return toAjax(ordOrderCommodityService.insertOrdOrderCommodity(ordOrderCommodity));
    }
    
    /**
     * 修改订单商品
     */
    @RequiresPermissions("applet:ordOrderCommodity:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap) {
        OrdOrderCommodity ordOrderCommodity = ordOrderCommodityService.selectOrdOrderCommodityById(id);
        mmap.put("ordOrderCommodity", ordOrderCommodity);
        return prefix + "/edit";
    }
    
    /**
     * 修改保存订单商品
     */
    @RequiresPermissions("applet:ordOrderCommodity:edit")
    @Log(title = "订单商品", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(OrdOrderCommodity ordOrderCommodity) {
        return toAjax(ordOrderCommodityService.updateOrdOrderCommodity(ordOrderCommodity));
    }
    
    /**
     * 删除订单商品
     */
    @RequiresPermissions("applet:ordOrderCommodity:remove")
    @Log(title = "订单商品", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(ordOrderCommodityService.deleteOrdOrderCommodityByIds(ids));
    }
}
